package thread;

// 继承 Thread, 重写 run
class MyThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("继承Thread类子线程被执行了 " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class demo1 {

    public static void main(String[] args) throws InterruptedException {
        // 1. 创建 Thread 实例
        // 创建 MyThread 类的实例
//        MyThread thread = new MyThread();
//        thread.start();

        // 向上转型
        Thread thread = new MyThread();

        // 2. 调用 start 方法, 启动线程
        thread.start();

        for (int i = 0; i < 10; i++) {
            System.out.println("主线程main方法被执行了 " + i);
            Thread.sleep(1000);
        }
    }
}
